package liu.db.oa.user.dao.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import liu.db.oa.user.dao.UserDao;
import liu.db.oa.user.entity.UserEntity;

public class UserDaoImpl implements UserDao {

	@Override
	public void add2 (UserEntity entity) throws Exception {
		//1.加载数据库驱动 
		Class.forName("com.mysql.jdbc.Driver");
		
		//url:你连接哪个数据库  ip地址+数据库的名字
		//
		Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/szrt", "root", "root");
		
		System.out.println(connection);
		
		//执行对应的sql
		String sql="insert into oa_user_t (NAME,AGE) VALUES ('"+entity.getName()+"',"+entity.getAge()+")";
		
		
		//让上面的sql真正插入到指定的数据库szrt
		PreparedStatement pr = connection.prepareStatement(sql);
		pr.executeUpdate();
		
		pr.close();
		connection.close();
	}
	
	
	
	
	@Override
	public void add(UserEntity entity) throws Exception {
		//1.加载数据库驱动 
		Class.forName("com.mysql.jdbc.Driver");
		
		//url:你连接哪个数据库  ip地址+数据库的名字
		//
		Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/szrt", "root", "root");
		
		System.out.println(connection);
		
		//执行对应的sql
		String sql="insert into oa_user_t (NAME,AGE) VALUES ('zxx',11)";
		
		
		//让上面的sql真正插入到指定的数据库szrt
		PreparedStatement pr = connection.prepareStatement(sql);
		pr.executeUpdate();
		
		pr.close();
		connection.close();
	}

}
